package com.jianguozh.difs.framework.model;

import cn.hutool.extra.servlet.ServletUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * 登录信息
 *
 * @author hanrs
 * @email 4076130@qq.com
 * @since 2022/6/20 10:43
 */
@Getter
@Setter
public class LoginInfo {

    /**
     * 账号
     */
    private String username;
    /**
     * 登录ip
     */
    private String loginIp;

    public LoginInfo(){
        HttpServletRequest request = ((ServletRequestAttributes) Objects
                .requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        this.loginIp = ServletUtil.getClientIP(request);
    }


}
